package com.ziyun.erp.web.modules.data.controller;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import io.renren.common.exception.RRException;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.data.entity.SellerEvaluateEntity;
import com.ziyun.erp.modules.data.service.SellerEvaluateService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 商户评价表
 *
 * @author zh
 * @email 
 * @date 2019-01-22 14:28:35
 */
@RestController
@RequestMapping("data/sellerevaluate")
public class SellerEvaluateController {
    @Autowired
    private SellerEvaluateService sellerEvaluateService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("data:sellerevaluate:list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = sellerEvaluateService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("data:sellerevaluate:info")
    public R info(@PathVariable("id") Long id){
        SellerEvaluateEntity sellerEvaluate = sellerEvaluateService.selectById(id);

        return R.ok().put("sellerEvaluate", sellerEvaluate);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("data:sellerevaluate:save")
    public R save(@RequestBody SellerEvaluateEntity sellerEvaluate){
        sellerEvaluateService.insert(sellerEvaluate);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("data:sellerevaluate:update")
    public R update(@RequestBody SellerEvaluateEntity sellerEvaluate){
        ValidatorUtils.validateEntity(sellerEvaluate);
        sellerEvaluateService.updateAllColumnById(sellerEvaluate);//全部更新
        
        return R.ok();
    }

    /**
     * 删除/屏蔽数据
     */
    @RequestMapping("/updateEvaluate")
    @RequiresPermissions("data:sellerevaluate:delete")
    public R updateEvaluate(@RequestBody Map<String ,Object> params){
        List<Long> ids = (List<Long>) params.get("ids");
        String type = params.get("type").toString();


        if (type.equals("0")){//
            SellerEvaluateEntity sellerEvaluateEntity = new SellerEvaluateEntity();
            sellerEvaluateEntity.setDelFlag(1);
            sellerEvaluateService.update(sellerEvaluateEntity, new EntityWrapper<SellerEvaluateEntity>()
                    .in("id", ids));
        }else if (type.equals("1")){ // 屏蔽
            SellerEvaluateEntity sellerEvaluateEntity = new SellerEvaluateEntity();
            sellerEvaluateEntity.setDisable(1);
            sellerEvaluateService.update(sellerEvaluateEntity, new EntityWrapper<SellerEvaluateEntity>()
                    .in("id", ids));
        }else {
            throw new RRException("未知操作!");
        }

        return R.ok();
    }

}
